//通用方法

const commonMethod = {
// 格式化时间
  formatDate(date) {
    if (!date) return "";
    const dateTime = new Date(date);
    const YY = dateTime.getFullYear();
    const MM =
      dateTime.getMonth() + 1 < 10
        ? '0' + (dateTime.getMonth() + 1)
        : dateTime.getMonth() + 1;
    const D =
      dateTime.getDate() < 10 ? '0' + dateTime.getDate() : dateTime.getDate();
    const hh =
      dateTime.getHours() < 10
        ? '0' + dateTime.getHours()
        : dateTime.getHours();
    const mm =
      dateTime.getMinutes() < 10
        ? '0' + dateTime.getMinutes()
        : dateTime.getMinutes();
    const ss =
      dateTime.getSeconds() < 10
        ? '0' + dateTime.getSeconds()
        : dateTime.getSeconds();
    return `${YY}-${MM}-${D} ${hh}:${mm}:${ss}`;
  },
  formatDate2(date) {
    const dateTime = new Date(date);
    const YY = dateTime.getFullYear();
    const MM =
      dateTime.getMonth() + 1 < 10
        ? '0' + (dateTime.getMonth() + 1)
        : dateTime.getMonth() + 1;
    const D =
      dateTime.getDate() < 10 ? '0' + dateTime.getDate() : dateTime.getDate();
    return `${YY}-${MM}-${D} `;
  },
  //yyyy-mm-dd 转换为时间戳
  timestampGet(timeString) {
    const thisTime = timeString.replace(/ /g, '/')
    let nowTime = new Date(thisTime)
    nowTime = nowTime.getTime()
    return nowTime
  },

}

export default commonMethod;
